import {
  IGoodsDetail,
  IGoodsDetailResonse,
  IGoodsRelevantResponse,
  ITemoraryResponse,
  ITemporary,
  ITemporaryParams,
  HotType,
  IHotGoodsResponse,
  IEvaluate,
  IEvaluateResponse,
  goodsCommentsListParams,
  IGoodsCommentInfo,
  IGoodCommentInfoResponse
} from './type/goods.type'
import request from '@/service/request'
import { IGoods } from './type/category.type'
const baseURL = 'https://mock.boxuegu.com/mock/1175/goods/'

export const findTemporary = (params: ITemporaryParams) => {
  return request<ITemporary, ITemoraryResponse>(
    '/category/goods/temporary',
    'post',
    params
  )
}
export const findGoodDetail = (id: string) => {
  return request<IGoodsDetail, IGoodsDetailResonse>('goods', 'get', { id })
}

/**
 * 获取商品同类推荐-未传入ID为猜喜欢
 * @param {String} id - 商品ID
 * @param {Number} limit - 获取条数
 */
export const findRelGoods = (id: string, limit = 16) => {
  return request<IGoods[], IGoodsRelevantResponse>('/goods/relevant', 'get', {
    id,
    limit
  })
}

/**
 * 获取热榜商品
 * @param {Number} type - 0代表24小时热销榜 1代表周热销榜 2代表总热销榜
 * @param {Number} limit - 获取个数
 */

 export const findHotGoods = (id:string,type:HotType, limit = 3) => {
  return request<IGoods,IHotGoodsResponse>('/goods/hot', 'get', {id, type, limit })
}

/**
 * 获取商品的评价统计信息
 * @param {String} id - 商品ID
 */
 export const findCommentInfoByGoods = (id:string) => {
  return request<IEvaluate,IEvaluateResponse>(`/${id}/evaluate`,'get',{},baseURL)
}

/**
 * 获取商品评价列表
 * @param{String} id - 商品ID
 * @param{goodsCommentsListParams} parmas -分页参数
 */

export const findGoodsCommentListById = (id:string,parmas:goodsCommentsListParams) =>{
  return request<IGoodsCommentInfo,IGoodCommentInfoResponse>(`${id}/evaluate/page`,'get',parmas,baseURL)
}